package org.tong.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.Date;

/**
 * @author
 * @date 2022-11-15 20:23
 */
@RestController
public class KafkaController {

    @Autowired
    private KafkaTemplate kafkaTemplate;


    @GetMapping("/send/{topic}/{msg}")
    public String sendMsg(@PathVariable(name = "topic") String topic, @PathVariable(name = "msg") String msg){
        kafkaTemplate.send(topic, msg);
        return String.format("topic:%s, msg:%s, %s", topic, msg, new Date());
    }
}
